using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Specialized;

namespace Core.Graphics
{
    public class CollisionTile
    {
        public bool SubterraneanCollision { get; set;  }
        public bool LandCollision { get; set;  }
        public bool WaterCollision { get; set; }
        public bool LowAirCollision { get; set; }
        public bool MidAirCollision { get; set; }
        public bool HighAirCollision { get; set; }

        public CollisionTile() { /*XML Serialization*/}

        //When we serialize this to XML we will want to do a custom serializer and then do a bit pack. We can easily pack
        //  all of these bool's into a single int so that each collision tile is represented by just a single int.

        /// <summary>Empty Collision Tile</summary>
        public static CollisionTile EmptyCollision { 
            get { if(_EmptyCollision == null) { _EmptyCollision = new CollisionTile(); } return _EmptyCollision; } }

        protected static CollisionTile _EmptyCollision;

        //Methods used for geting collision tile data for serializing
        public static int GetCollisionTileAsBitVector(CollisionTile CTile)
        {
            BitVector32 bv = new BitVector32();
            bv[0] = CTile.SubterraneanCollision;
            bv[3] = CTile.LandCollision;
            bv[6] = CTile.WaterCollision;
            bv[8] = CTile.LowAirCollision;
            bv[9] = CTile.MidAirCollision;
            bv[10] = CTile.HighAirCollision;

            return bv.Data;
        }

        public static CollisionTile GetCollisionTileFromBitVector(int Data)
        {
            BitVector32 BitVector = new BitVector32(Data);

            CollisionTile CTile = new CollisionTile();
            CTile.SubterraneanCollision = BitVector[0];
            CTile.LandCollision = BitVector[3];
            CTile.WaterCollision = BitVector[6];
            CTile.LowAirCollision = BitVector[8];
            CTile.MidAirCollision = BitVector[9];
            CTile.HighAirCollision = BitVector[10];

            return CTile;
        }
    }

    public class CollisionTileCollection : Collection<CollisionTile> 
    {
        public static CollisionTileCollection GetCollisionTilesForEmptyCollisionLayer(int Width, int Height)
        {
            CollisionTileCollection ctc = new CollisionTileCollection();

            for (int x = 0; x < Width * Height; x++)
            {
                ctc.Add(CollisionTile.EmptyCollision);
            }

            return ctc;
        }
    }
}
